package com.example.recyclerviewproject;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewDecorationAct extends AppCompatActivity {
   // 二十四节气即：立春、 雨水、惊蛰、春分、清明、谷雨、立夏、小满、芒种、夏至、小暑、大暑、立秋、处暑、白露、秋分、寒露、霜降、立冬、小雪、大雪、冬至、小寒、大寒。
   private String[] solarTermTexts={"立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑",
                                    "立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒"};
    private Integer[] solarTermImages = {R.mipmap.lichun,R.mipmap.yushui,R.mipmap.jingzhe,R.mipmap.chunfen,R.mipmap.qingming,R.mipmap.guyu,
                              R.mipmap.lixia,R.mipmap.xiaoman,R.mipmap.mangzhong,R.mipmap.xiazhi,R.mipmap.dongzhi,R.mipmap.xiaoshu,R.mipmap.dashu,
                              R.mipmap.liqiu,R.mipmap.chushu,R.mipmap.bailu,R.mipmap.qiufen,R.mipmap.hanlu,R.mipmap.jiangshuang,
                              R.mipmap.lidong,R.mipmap.xiaoxue,R.mipmap.dashu,R.mipmap.dongzhi,R.mipmap.xiaohan,R.mipmap.dahan};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview_decoration_layout);
        // No Titlebar
        getSupportActionBar().hide();
        //*初始化RecyclerView控件
        RecyclerView mRecyclerView = findViewById(R.id.mRecyclerView);
        //*创建布局管理器
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //设置为垂直布局，这也是默认的
        layoutManager.setOrientation(RecyclerView. VERTICAL);
        //水平
      //  layoutManager.setOrientation(RecyclerView.HORIZONTAL);
        //网格布局
      //  GridLayoutManager layoutManager2 = new GridLayoutManager(this,3);
        //*设置布局管理器
        mRecyclerView.setLayoutManager(layoutManager);
        //准备数据
        List<ItemBean> list = new ArrayList<>();
        for (int i = 1; i <=24; i++) {
            ItemBean itemBean = new ItemBean();
           // itemBean.setImageInt(R.mipmap.new_icon);
            itemBean.setImageInt(solarTermImages[i-1]); //设置本地图片
            //itemBean.setTitle("标题"+i);
            itemBean.setTitle(solarTermTexts[i-1]);
            itemBean.setContent("内容===="+i);
            list.add(itemBean);
        }
        //*创建适配器
        MyAdapter myAdapter = new MyAdapter(this);
        //*给适配器传数据作为列表数据
        myAdapter.setList(list);
        //*设置RecyclerView的适配器
        mRecyclerView.setAdapter(myAdapter);
        //分割线
       DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, RecyclerView.VERTICAL);
       //给列表设置分割线
      mRecyclerView.addItemDecoration(dividerItemDecoration);


    }
}
